package com.hskn.hss.module.tlthresholdtrans.controller;


import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.hskn.hss.core.annotation.SysLog;
import com.hskn.hss.core.enums.BusinessType;
import com.hskn.hss.entity.AjaxResult;
import com.hskn.hss.exception.HssException;
import com.hskn.hss.module.tlcostoperate.mapper.TlCostOperateMapper;
import com.hskn.hss.module.tlfacilitietype.entity.TlFacilitiesType;
import com.hskn.hss.module.tlthresholdtrans.entity.TlThresholdTrans;
import com.hskn.hss.module.tlthresholdtrans.mapper.TlThresholdTransMapper;
import com.hskn.hss.module.tlthresholdtrans.service.ITlThresholdTransService;
import com.hskn.hss.utils.Tools;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;

/**
 * <p>
 * 前端控制器
 * </p>
 *
 * @author hskn
 * @since 2021-05-13
 */
@Slf4j
@RestController
@RequestMapping("/hss/tlthresholdtrans")
public class TlThresholdTransController {

    @Autowired
    ITlThresholdTransService tlThresholdTransService;

    @SysLog(businessType = BusinessType.INSERT, tableName = "tl_threshold_trans", bean = TlThresholdTrans.class, beanMapper = TlThresholdTransMapper.class, names = "id")
    @RequestMapping(value = "insert", method = RequestMethod.POST)
    public AjaxResult<Object> insert(HttpServletRequest request) {
        try {
            JSONObject params = JSON.parseObject(Tools.getBody(request));
            return tlThresholdTransService.insert(params);
        } catch (HssException e) {
            e.printStackTrace();
            log.error("报错ERROR", e);
            return AjaxResult.fail("操作失败，请稍后再试");
        }
    }

    @SysLog(businessType = BusinessType.UPDATE, tableName = "tl_threshold_trans", idKey = "id", bean = TlThresholdTrans.class, beanMapper = TlThresholdTransMapper.class, names = "id")
    @RequestMapping(value = "update", method = RequestMethod.POST)
    public AjaxResult<Object> update(HttpServletRequest request) {
        try {
            JSONObject params = JSON.parseObject(Tools.getBody(request));
            return tlThresholdTransService.update(params);
        } catch (HssException e) {
            e.printStackTrace();
            log.error("报错ERROR", e);
            return AjaxResult.fail("操作失败，请稍后再试");
        }
    }


    @RequestMapping(value = "getDetail", method = RequestMethod.POST)
    public AjaxResult<Object> getDetail(HttpServletRequest request) {
        JSONObject params = JSON.parseObject(Tools.getBody(request));
        TlThresholdTrans tlThresholdTrans = null;
        try {
            tlThresholdTrans = tlThresholdTransService.getDetail(params);
        } catch (HssException e) {
            e.printStackTrace();
            log.error("报错ERROR", e);
            return AjaxResult.fail("获取信息失败，请稍后再试");
        }
        return AjaxResult.success(tlThresholdTrans);

    }

    @RequestMapping(value = "getTrans", method = RequestMethod.POST)
    public AjaxResult<Object> getTrans(HttpServletRequest request) {
        JSONObject params = JSON.parseObject(Tools.getBody(request));
        String code = params.getString("code");
        String num = params.getString("num");
        try {
            String tlThresholdTrans = tlThresholdTransService.getTrans(code, num);
            return AjaxResult.success(tlThresholdTrans);
        } catch (Exception e) {
            e.printStackTrace();
            log.error("报错ERROR", e);
            return AjaxResult.fail("获取信息失败，请稍后再试");
        }


    }
}

